import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { ValidateProvider } from "../../providers/validate/validate";
import { ConfigProvider } from "../../providers/config/config";
import { StorageProvider } from "../../providers/storage/storage";
import { HttpServicesProvider } from "../../providers/http-services/http-services";
import { UtilsProvider } from "../../providers/utils/utils";

/**
 * Generated class for the GuidePage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-guide',
  templateUrl: 'guide.html',
})
export class GuidePage {

                constructor(
                  public navCtrl: NavController,
                  public navParams: NavParams,
                  public validate: ValidateProvider,
                  public config: ConfigProvider,
                  public storage: StorageProvider,
                  public httpService: HttpServicesProvider,
                  public util: UtilsProvider
                ) {
                  if (!this.validate.checkLogin()) {
                    this.navCtrl.push('LoginPage');
                  }
                }

                //判断用户是否登录
                ionViewCanEnter() {
                  return this.validate.checkLogin();
                }

                userInfo = this.config.userInfoHolder;
                ionViewWillEnter() {
                  if (!this.validate.checkLogin()) {//登录
                    this.navCtrl.push('LoginPage', { 'backPage': 'MemberPage' });
                  } else {
                    this.getData(null);
                  }
                }

                page = 1;
                lists = [];
                getData(infiniteScroll) {
                  this.httpService.requestPostData('/user_info/my_comment', {
                    token: this.config.getToken(),
                    type_id: "27,54",
                    page: this.page
                  }, response => {
                    //全部数据
                    this.lists = this.lists.concat(response['data']['lists']);
                    this.page++;
                    if (infiniteScroll) {
                      infiniteScroll.complete();   /*请求完成数据更新页面*/
                      if (response['data']['lists'].length < response['data']['lists']) {   /*没有数据 禁用上拉更新*/
                        infiniteScroll.enable(false);
                      }
                    }
                  });
                }

                doInfinite(infiniteScroll) {
                  this.getData(infiniteScroll);
                }

}
